package activity

import (
	"activity_srv/activityclient"
	"api/internal/respons"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateGrouponProductLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateGrouponProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateGrouponProductLogic {
	return &CreateGrouponProductLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateGrouponProductLogic) CreateGrouponProduct(req *types.CreateGrouponProductRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	product, err := l.svcCtx.ActivityRpc.CreateGrouponProduct(l.ctx, &activityclient.CreateGrouponProductRequest{
		ProductName:   req.ProductName,
		ProductPrice:  float32(req.ProductPrice),
		GroupPrice:    float32(req.GroupPrice),
		MemberNum:     req.MemberNum,
		Status:        req.Status,
		ActivityStart: req.ActivityStart,
		ActivityEnd:   req.ActivityEnd,
		CoverImage:    req.CoverImage,
		ProductStock:  req.ProductStock,
	})
	if err != nil {
		return respons.Error(400, "添加失败", err.Error()), err
	}
	return respons.Success(product), nil
}
